
// 图片转base64
export const imageToBase64 = (path) => {
  // #ifdef APP-PLUS
  return new Promise((resolve, reject) => {
    plus.io.resolveLocalFileSystemURL(path, function(entry) {
      entry.file(function(file) {
        var fileReader = new plus.io.FileReader();
        fileReader.readAsDataURL(file);
        fileReader.onloadend = function(evt) {
          resolve(evt.target.result);
        }
      })
    })
  })
  // #endif

  // #ifdef H5
  return new Promise((resolve, reject) => {
    uni.request({
      url: path,
      method: 'GET',
      responseType: 'arraybuffer',
      success: res => {
        let base64 = uni.arrayBufferToBase64(res.data); //把arraybuffer转成base64
        base64 = 'data:image/jpeg;base64,' + base64
        resolve(base64)
      },
      fail: err => {
        reject(err)
      }
    })
  })
  // #endif
}